<template>
  <el-upload
  class="avatar-uploader jx-uploader"
  name="imgFile"
  :headers="headers"
  :action="`${$api.common.upload}?catalog=index_img`"
  :show-file-list="false"
  :on-success="handleSuccess">
  <img v-if="(img != '') && (img)" :src="img" class="avatar">
  <i v-else class="el-icon-plus avatar-uploader-icon"></i>
  </el-upload> 
</template>
<script>
export default {
  props: {
    img: String
  },
  data(){
    return {
      headers: {
        'institution-auth-token': localStorage.getItem('ms_token') || ''
      },
    }
  },
  mounted(){
    let _self = this
  },
  methods: {
    handleSuccess(res){
      let _self = this
      if(!res) return
      if(res.retCode == 1){
        let params = {}
        _self.img = res.retObject.defaultImgDetail.path
        params.path = res.retObject.defaultImgDetail.path
        params.id = res.retObject.imgId
        _self.$emit('upload', params)
      }else{
        _self.$message.error(res.retMsg)
      }
    },
  }
}
</script>
<style scoped lang="sass">
/deep/ .el-form-item__content img
  max-width: inherit
  max-height: inherit
/deep/ .el-upload--picture-card
  width: 100px
  line-height: inherit
/deep/ .el-upload-list--picture-card .el-upload-list__item
  width: 100px
  height: 100px
</style>